package LeetCode;

import java.util.ArrayList;
import java.util.List;

public class LeetCodeMain28 {
    public List<Integer> partitionLabels(String s) {
        int[] arr=new int[27];
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            arr[ch-'a']=i;
        }
        List<Integer> list=new ArrayList<>();
        int left=0;
        int right=0;
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            right=Math.max(right,arr[ch-'a']);
            if (i == right) {
                list.add(right - left + 1);
                left = i + 1;
            }
        }
        return list;
    }
}